package controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * Author：汤小洋
 * Date：2022-11-25 10:10
 * Description：<描述>
 */
@Controller
@RequestMapping("/path")
public class PathController {

    /**
     * 基本用法
     */
    @RequestMapping("/test1")
    public String test1(){
        System.out.println("PathController.test1");
        return "success";
    }

    /**
     * 配置URL时以/开头和不以/开头的区别
     */
    @RequestMapping("/test2")
    public String aaaa(){
        System.out.println("PathController.aaaa");
        // return "forward:/test1"; // 不行
        // return "forward:test1";
        return "forward:/path/test1";
    }

    /**
     * 请求映射路径的写法
     */
    // @RequestMapping("/test3")
    // @RequestMapping(value = "/test3")
    // @RequestMapping(path = "/test3")
    @RequestMapping(path = {"/test3","/t3"})
    public String test3(){
        System.out.println("PathController.test3");
        return "success";
    }

    /**
     * Rest风格的url
     */
    // @RequestMapping("/test4/aa/bb")
    @RequestMapping("/test4/{sex}/{age}")
    // public String test4(){
    public String test4(String name,@PathVariable String sex,@PathVariable int age){
    //     System.out.println("PathController.test4");
        System.out.println("PathController.test4............."+name+","+sex+","+age);
        return "sucess";
    }

    /**
     * 限定请求方式
     */
    // @RequestMapping(value = "/test5", method = RequestMethod.POST)
    // @PostMapping("/test5")
    @GetMapping("/test5")
    public String test5(){
        System.out.println("PathController.test5");
        return "success";
    }


}
